package com.base.controller;

import java.io.IOException;
import java.text.ParseException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.base.comm.CommContent;
import com.base.po.voip.ShopText;
import com.base.po.voip.Shopinfoes;
import com.base.service.LogsService;
import com.base.service.ShopTextService;
import com.base.service.ShopinfoService;
import com.base.utils.IP;
import com.base.utils.Produce;

/**
 * 添加滚动文字信息服务端
 * 
 * @author f
 *
 */
@Controller
@RequestMapping("/admin")
public class add_Roll {

	@Autowired
	private LogsService logsService;// log日志
	@Autowired
	private ShopTextService shopTextService; // 商城滚动文字信息
	@Autowired
	private ShopinfoService shopinfoService; // 发现滚动文字信息

	// 添加商城滚动文字
	@RequestMapping(value = "/toAddMallroll", method = RequestMethod.POST)
	public @ResponseBody int toAddMallroll(HttpServletRequest request, String text)
			throws IOException, ParseException {
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (userid == null) return -1; // 未登录
		if (shopTextService.selectByAll(new ShopText(true, 2, userid)).size() >= 4) return -2;// 判断是否存在4条
		logsService.insert(CommContent.TYPE_CREATE, CommContent.LOGS_XIAOXI + "配置商城滚动文字信息",
				(String) request.getSession().getAttribute("userNick"), true, IP.getIpAddr(request));
		return shopTextService.insert(new ShopText(Produce.getUUID(), text, null, true, 2, userid, null)); // 添加
	}

	// 添加发现滚动文字
	@RequestMapping(value = "/toAddFindroll", method = RequestMethod.POST)
	public @ResponseBody int toAddFindroll(HttpServletRequest request, String text)
			throws IOException, ParseException {
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (userid == null) return -1; // 未登录
		if (shopinfoService.selectByAll(new Shopinfoes(true, 2, userid)).size() >= 4) return -2; // 判断是否存在4条
		logsService.insert(CommContent.TYPE_CREATE, CommContent.LOGS_XIAOXI + "配置发现滚动文字信息",
				(String) request.getSession().getAttribute("userNick"), true, IP.getIpAddr(request));
		return shopinfoService.insert(new Shopinfoes(Produce.getUUID(), userid, null, text, null, 2, true, 0)); // 添加
	}
}
